package com.example.app1;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class MyPagerAdapter extends FragmentPagerAdapter {

    MainFragment mainFragment;
    SettingsFragment settingsFragment;

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        if (this.mainFragment == null) {
            this.mainFragment = new MainFragment();
        }
        if (this.settingsFragment == null) {
            this.settingsFragment = new SettingsFragment();
        }
        switch (position) {
            case 0:
                return this.mainFragment;
            case 1:
                return this.settingsFragment;
            default:
                return null;
        }
    }

    @Override
    public int getCount() {
        return 2; // MainFragment and SettingsFragment
    }
}
